package io.dy.util;

import io.dy.custom.MyQueue;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collector;

/**
 * @author : dmj
 * @date: 2024/12/20 3:29 下午
 * @description: lambda工具类
 */
public class Lambda {


    public void ss(){
        Collector<Integer, MyQueue<Integer>, MyQueue<Integer>> myQueueSupplier = Collector.of(
                () -> new MyQueue<Integer>(Comparator.comparing(Function.identity()), 10),
                (BiConsumer<MyQueue<Integer>, Integer>) PriorityQueue::add,
                (q1, q2) -> q2
        );
    }


    public static<T,R extends Comparable<? super R>> Collector<T, MyQueue<T>, MyQueue<T>> top(Function<T,R> function, int topNum){
        return Collector.of(
                () -> new MyQueue<>(Comparator.comparing(function), topNum),
                MyQueue::offer,
                (q1,q2)-> q1
        );
    }


    public static<T,R extends Comparable<? super R>> Collector<T, MyQueue<T>, MyQueue<T>> top(Function<T,R> function){
        return top(function, 10);
    }


    public static void main(String[] args) {

            for (int i = 0; i < 20; i++) {
                System.out.println("第一层循环:" + i);
                for (int j = 0; j < 20; j++) {
                    System.out.println("\t 第二层循环:" + j);
                    if(i*j == 72){
                        System.out.println("查询到数据。。。。");
                        break;
                    }
                }
            }
    }
}
